package db.tables.reference;

import java.sql.SQLException;
import java.util.ArrayList;

import org.hsqldb.Types;

import db.DBObject;
import db.tables.DBGroupTable;
import db.tables.DBUserTable;

public class DBGroupMemberTable extends DBObject {
	public static final String TABLE_NAME = "group_member";

	public static final String GROUP_MEMBER_ID_COL = TABLE_NAME + "_id",
			GROUP_ID_COL = DBGroupTable.GROUP_ID_COL,
			USER_ID_COL = DBUserTable.USER_ID_COL,
			START_DATE_COL = "start_date", END_DATE_COL = "end_date";

	public DBGroupMemberTable() throws ClassNotFoundException, SQLException {
		super(TABLE_NAME, new Object[][] {
				{ GROUP_MEMBER_ID_COL, Types.BIGINT, SQL_IDENTITY_PRIMARY_KEY,
						"" },
				{ GROUP_ID_COL, Types.BIGINT, SQL_NOT_NULL, "" },
				{ USER_ID_COL, Types.BIGINT, SQL_NOT_NULL, "" },
				{ START_DATE_COL, Types.DATE, SQL_NOT_NULL, "" },
				{ END_DATE_COL,	Types.DATE, getSQLCheckEndDate()
					+getSQLForeignKeyReference(DBGroupTable.TABLE_NAME,GROUP_ID_COL)
					+getSQLForeignKeyReference(DBUserTable.TABLE_NAME,USER_ID_COL),	"" } });
	}
	
	public ArrayList<ArrayList<Object>> getArrayListByUserID(Long user_id){
		return getReferenceTableJoin(tableName, DBGroupTable.TABLE_NAME, 
				getAbsoluteColumn(GROUP_ID_COL), 
				getAbsoluteColumn(DBGroupTable.TABLE_NAME, DBGroupTable.GROUP_ID_COL), 
				getAbsoluteColumn(USER_ID_COL),user_id);
	}
}
